<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>   
<%
String path = request.getContextPath();  
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>
  <head>
    <base href="<%=basePath%>">  
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	
	<meta http-equiv="description" content="This is my page">
	
	<link rel="stylesheet" type="text/css" href="css/edittable.css"  ></link>  
	<link rel="stylesheet" type="text/css" href="css/validate.css"  ></link>  
	<script type="text/javascript"  src="js/jquery-1.8.0.js"></script>
	<script >
		$(function(){
			var cateName=false;//设置全局变量   提交验证时候用  初始值设置false  防止开始就提交
<!-- 提交按钮点击事件 begin -->			
			$("input[type=submit]").click(function(){
				var result=true;
				if(cateName==false){
					$("#cateName").blur();
					result = false;
				}
				var session = '${admin_session}';
				if(session!=""){
					if(result==true){
							if(confirm("确认提交吗")){
								$.ajax({
									url:"CateServlet.do",
									type:"post",
									data:{cateName:$("#cateName").val(),flag:"addCateBig",note:$(".txtarea").val()},
									success:function(data){
										$("#result_msg").html(data).removeClass().addClass("validate_ok");
									}
								});
						}
					}else{
						$("#result_msg").html("请正确填写信息后提交").removeClass().addClass("validate_error");
					}
				}else{
					window.location.href="login.jsp";
				}
			});
<!-- 提交按钮点击事件 end -->	

<!-- 分类名称blur事件 begin -->	
			$("#cateName").blur(function(){
				var id = $(this)[0].id;
				var name=$(this).val();
				var reg=/^\S{2,20}$/g;
				if(reg.test(name)){
					$.ajax({
						url:"CateServlet.do",
						type:"post",
						data:{cateName:$(this).val(),flag:"cateFlag"},
						success:function(data){
							
							if(data!=""){
								$("#"  +id+"_msg").html(data).removeClass().addClass("validate_error");
								cateName=false;
							}else{
								$("#"  +id+"_msg").html("√").removeClass().addClass("validate_ok");
								cateName=true;
							}
						}
					});
				}else{
					$("#"+id +"_msg").html("格式错误").removeClass().addClass("validate_error");
					cateName=false;
				}
			});
<!-- 分类名称blur事件 end -->	
			$("input[type=reset]").click(function(){
				window.location.href="cate/bigcate_add.jsp";
			});
		});
	</script>
   </head>
  
  <body>
  	 <div class ="div_title">
		 <div class="div_titlename"> <img src="images/san_jiao.gif" ><span>添加一级分类</span></div>
	 </div>
				 
	 <table class="edit_table" >
 		<tr>
 			 	<td class="td_info">分类名称:</td>	
 			 	<td class="td_input_short"> 
 			 		<input type="text" class="txtbox" id="cateName" name="cateName" /> 
 			 	</td>   
 			 	<td>
 			 		<label class="validate_info" id="cateName_msg" >长度2~20位为空白字符</label>
 			 	</td> 
 		</tr>
 			<tr>
 				<td class="td_info">分类描述:</td>	
 				<td>
 					<textarea rows="4" cols="27" class="txtarea" name="note"></textarea>
 				</td> 
 				<td></td>	
 		</tr>
 		<tr>
 			<td class="td_info"> </td>	
 			<td> 
 			<input class="form_btn" type="submit" value="提交" /> 
 			<input type="reset"  class="form_btn" value="重置" /> </td>	
 			<td>
 				<label id="result_msg" class="result_msg"></label>
 			</td>	
 		</tr>
	</table>
  </body>
</html>